package view.diaLogView;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.administrator.text.R;

import java.io.IOException;

import util.HomeUtil;
import util.NetWorkstateUtil;
import util.Url;
import util.fileUtil.SelectFiles;

/**
 * Created by Administrator on 2016/8/10.
 * 上传日志
 */
public class UploadLogDialog extends Dialog{
    private Context mContext;
    private UploadLogDialog mNoNetDialog;
    private String mFwq;
    @Override public void show() {
        Window window = getWindow();
        window.setGravity(Gravity.BOTTOM);
        super.show();
    }
    protected UploadLogDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    public UploadLogDialog(Context context,String fwq) {
        super(context, R.style.upoad_dialog);
        this.mContext = context;
        mNoNetDialog = this;
        mFwq = fwq;
    }

    @Override protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        init();
    }

    private void init() {
        ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        params.width = mContext.getResources().getDisplayMetrics().widthPixels;
        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View mView = inflater.inflate(R.layout.nonet_dialog, null);
        TextView textView1 = (TextView)mView.findViewById(R.id.text_nonet_no);  //取消
        TextView textView2 = (TextView)mView.findViewById(R.id.text_nonet_yes);//确定
        LinearLayout linearLayout2 = (LinearLayout)mView.findViewById(R.id.linear_upload2);

        textView2.setOnClickListener(new View.OnClickListener() {
            @Override public void onClick(View v) {
                mNoNetDialog.dismiss();
                try {
                    SelectFiles.getNewSelectFiles().getFileUpload(mContext,mFwq);
                    //BuglyLog.e("Bject", "  "+mFwq);
                } catch (IOException e) {
                    e.printStackTrace();
                }

                 /*if(android.os.Build.VERSION.SDK_INT > 10 ){
                    //3.0以上打开，设置界面
                    mContext.startActivity(new Intent(android.provider.Settings.ACTION_SETTINGS));
                }else
                {
                    mContext.startActivity(new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS));
                }*/
            }
        });
        textView1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mNoNetDialog.dismiss();
                brokenNetwork();
            }
        });
        linearLayout2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mNoNetDialog.dismiss();
                brokenNetwork();
            }
        });
        setContentView(mView, params);
    }

    private void brokenNetwork(){
        if(Url.getUrlNew().getNETWORKING_ATATE() == 1){
            NetWorkstateUtil.getInstance().getBrokenNetwork(mContext, new HomeUtil.OnHomeUtilClickListener() {
                @Override
                public void onItemClick(String type) {
                    if(type.equals("ok")){
                        Url.getUrlNew().setNETWORKING_ATATE(0);
                    }
                }
            },1);
        }
    }
}
